package com.web.services;
import com.web.beans.DictionaryValue;
import com.web.dao.DictionaryValueDao;
import com.web.exception.MyException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class DictionaryValueServicesImp implements DictionaryValueServices {

    @Autowired
    DictionaryValueDao dictionaryValueDao;


    @Override
    public ArrayList<DictionaryValue> getAll() {
        return dictionaryValueDao.getAll();
    }

    @Override
    public DictionaryValue get(String id) throws MyException {
        DictionaryValue dictionaryValue = dictionaryValueDao.get(id);
        if (dictionaryValue == null) {
            throw new MyException(BaseServices.ERROR_MESS_NO_QUERY);
        }
        return dictionaryValue;
    }

    @Override
    public void add(DictionaryValue dictionaryValue) throws MyException {

        int add = dictionaryValueDao.add(dictionaryValue);
        if(add<=0){
            throw new MyException(BaseServices.ERROR_MESS_ADD_NOTROWS);
        }
    }

    @Override
    public void edit(DictionaryValue dictionaryValue) throws MyException {
        int edit = dictionaryValueDao.edit(dictionaryValue);
        if(edit<=0){
            throw new MyException(BaseServices.ERROR_MESS_EDIT_NOTROWS);
        }
    }

    @Override
    public void del(String id) throws MyException {
        int del = dictionaryValueDao.del(id);
        if(del<=0){
            throw new MyException(BaseServices.ERROR_MESS_DEL_NOTROWS);
        }
    }
}
